package graphics.complexe;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;

import colors.Color;

import utils.Point3D;
import utils.Vector3D;
import graphics.engine.ProgramShader;
import graphics.primitive.BasePrimitive;

public abstract class BaseGraphicObject 
{
	protected BasePrimitive shape;
	protected BasePrimitive outline;
	protected BasePrimitive selectionShape;
	
	private Point3D position;
	
	private Vector3D scale;
	private boolean hasTexture;
	private Integer texture;
	
	public BaseGraphicObject()
	{
		this.position = new Point3D();
		this.scale = new Vector3D();
	}

	public Vector3D getScale() {
		return scale;
	}

	public void setScale(Vector3D scale) {
		this.scale = scale;
		this.shape.setScale(scale);
		this.outline.setScale(scale);
		this.selectionShape.setScale(new Vector3D(scale.x(), scale.y(), scale.z()));
	}
	
	public Color getBaseColor() {
		return this.shape.getColor();
	}

	public void setBaseColor(Color baseColor) {
		this.shape.setColor(baseColor);
	}

	public Color getOutlineColor() {
		return this.outline.getColor();
	}

	public void setOutlineColor(Color outlineColor) {
		this.outline.setColor(outlineColor);
	}
	
	public void Draw(GLAutoDrawable drawable, ProgramShader program)
	{
		this.shape.Draw(drawable, program);
		this.outline.Draw(drawable, program);
	}
	
	public void DrawSelection(GLAutoDrawable drawable, ProgramShader program)
	{
		this.selectionShape.Draw(drawable, program);
	}
	
	public void setPosition(Point3D position)
	{
		this.position = position;
		this.shape.setPosition(position);
		this.outline.setPosition(position);
		this.selectionShape.setPosition(position);
	}
	
	public void DrawHighlight(GLAutoDrawable drawable, ProgramShader program)
	{
		GL gl = drawable.getGL();
		gl.glLineStipple(1, (short) 0x00FF);  
		gl.glEnable(GL.GL_LINE_STIPPLE);
		this.selectionShape.Draw(drawable, program);
			
		gl.glDisable(GL.GL_LINE_STIPPLE);
	}
	
	public Integer getTexture() {
		return texture;
	}

	public void setTexture(Integer texture) {
		this.setHasTexture(( texture != null));
		if(texture != null)
		{
			this.texture = texture;
			this.shape.setTexture(texture);
		}
	}

	public boolean hasTexture() {
		return hasTexture;
	}

	public void setHasTexture(boolean hasTexture) {
		this.hasTexture = hasTexture;
	}
}
